package sample.road;

import java.util.Set;

public class Road {

	private String no;
	private Node startNode;
	private Node endNode;
	
	private Set<Road> ingressRoads;
	private Set<Road> egressRoads;
	
	private double length;
	private Road dstRoad;
	
	public String getNo() {
		return no;
	}
	
	public Road(String type, String no, Node startNode, Node endNode) {
		this.no = no;
		this.startNode = startNode;
		this.endNode  = endNode;
		
		length = Math.sqrt(
			Math.pow((Double.valueOf(startNode.getX()) - Double.valueOf(endNode.getX())), 2)
			+
			Math.pow((Double.valueOf(startNode.getY()) - Double.valueOf(endNode.getY())), 2)
		);
	}

	public void setDstRoad(Road road) {
		if (dstRoad != null) {
			throw new RuntimeException("duplicate assignment : road " + road);
		}
		this.dstRoad = road;
	}

	@Override
	public String toString() {
		return "Road [no=" + no + ", startNode=" + startNode + ", endNode="
				+ endNode + ", ingressRoads=" + ingressRoads + ", egressRoads="
				+ egressRoads + ", length=" + length + ", dstRoad=" + dstRoad.getNo()
				+ "]";
	}
	
	

}
